﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CADprogram.Base
{
    public class ViewManager
    {
        static Matrix conversionMatrix = new Matrix();
        static Matrix matrixRotate = new Matrix();//旋转变换矩阵
        static Matrix matrixPan = new Matrix();
        static Matrix matrixScale = new Matrix();
        static  Matrix invConversionMatrix = new Matrix();
         static  float scale = 1;//表示 Scale=m  即 比例尺  1/scale
        public static Matrix Matrix_Rotate
        {
            get { return matrixRotate; }
            set { matrixRotate = value; }
        }
        public static Matrix MatrixPan
        {
            get { return matrixPan; }
            set { matrixPan = value; }
        }
        public static Matrix InvMatrixPan
        {
            get {
                Matrix matrix = matrixPan.Clone();
                matrix.Invert();
                return matrix;
            }
        }
        public static Matrix InvMatrixRotate
        {
            get
            {
                Matrix matrix = matrixRotate.Clone();
                matrix.Invert();
                return matrix;
            }
        }
        public static Matrix InvMatrixScale
        {
            get {
                Matrix matrix = matrixScale.Clone();
                matrix.Invert();
                return matrix;
            }
        }
        public static Matrix set_Rotate(float angle)
        {
            matrixRotate.Rotate(angle, MatrixOrder.Append);
            return matrixRotate;
        }
        public static Matrix Set_pan(float dx, float dy)
        {
            matrixPan.Translate(dx, dy, MatrixOrder.Append);
            return matrixPan;
        }
        public static Matrix Reset_pan()
        {
            matrixPan.Translate(-matrixPan.OffsetX, -matrixPan.OffsetY);
            return matrixPan;
        }
        public static float Scale
        {
           get { return scale; }
            set { scale = value; }
        }
        public static Matrix InvConversionMatrix
        {
            get
            {
                invConversionMatrix = ConversionMatrix.Clone();
                invConversionMatrix.Invert();
                return invConversionMatrix;
            }
        }
        public static Matrix ConversionMatrix
        {
            get {
                conversionMatrix.Reset();
                conversionMatrix.Multiply(matrixRotate);
                conversionMatrix.Multiply(matrixPan);
                matrixScale.Reset();
                matrixScale.Scale(1 / scale, 1 / scale);
                conversionMatrix.Multiply(matrixScale);
                return conversionMatrix;
            }

        }
        //方法
        public ViewManager()
        {
            // matrixRotate.Rotate(-90, MatrixOrder.Append);//初始化的坐标点
            Reset_pan();
            matrixPan.Translate(0, 0);
            matrixScale.Scale(1/scale,1/scale);
        }
        
        //测试方法
    }
}
